<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css}" rel="stylesheet"/>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-announcement-edit" th:object="${announcement}">
            <input id="id" name="id" th:field="*{id}"  type="hidden">
			<div class="form-group">	
				<label class="col-sm-3 control-label">标题：</label>
				<div class="col-sm-8">
					<input id="title" name="title" th:field="*{title}" class="form-control" type="text">
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">状态：</label>
				<div class="col-sm-8">
					<div class="radio-box" th:each="dict : ${@dict.getType('sys_status')}">
						<input type="radio" th:id="${dict.dictCode}" name="status" th:value="${dict.dictValue}" th:field="*{status}">
						<label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
					</div>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">生效开始时间：</label>
				<div class="col-sm-8">
					<li class="select-time">
						<input type="text" class="time-input" id="effectiveFromTime" th:value="${#dates.format(announcement.effectiveFromTime, 'yyyy-MM-dd')}"   placeholder="开始时间" name="effectiveFromTime"/>
					</li>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">生效结束时间：</label>
				<div class="col-sm-8">
					<li class="select-time">
						<input type="text" class="time-input" id="effectiveToTime" th:value="${#dates.format(announcement.effectiveToTime, 'yyyy-MM-dd')}"    placeholder="开始时间" name="effectiveToTime"/>
					</li>

				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">内容：</label>
				<div class="col-sm-8" >
					<textarea id="content" name="content" class="form-control">[[*{content}]]</textarea>
				</div>
			</div>

		</form>
    </div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">



		var prefix = ctx + "system/announcement"
		$("#form-announcement-edit").validate({
			rules:{
				title:{
					required:true,
				},
				status:{
					required:true,
				},
				effectiveFromTime:{
					required:true,
				},
				effectiveToTime:{
					required:true,
				},
				content:{
					required:true,
				},
			}
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
				var id = $("input[name='id']").val();
				var title = $("input[name='title']").val();
				var status = $("input[name='status']").is(':checked') == true ? '10A' : '10B';

				var effectiveFromTime = $("input[name='effectiveFromTime']").val();
				var effectiveToTime = $("input[name='effectiveToTime']").val();
				var content = $("#content").val();

				$.ajax({
					cache: true,
					type: "POST",
					timeout: 13000, //超时时间设置，单位毫秒
					url: ctx + "system/announcement/edit",
					data: {
						"id": id,
						"title": title,
						"status": status,

						"effectiveFromTime": effectiveFromTime,
						"effectiveToTime": effectiveToTime,
						"content": content
					},
					async: false,
					error: function (request) {
						$.modal.alertError("系统错误");
					},
					success: function (data) {
						$.operate.successCallback(data);
					},
					complete: function (XMLHttpRequest, status) { //请求完成后最终执行参数
						if (status == 'timeout') {//超时,status还有success,error等值的情况
							ajaxTimeoutTest.abort();
							alert("超时");
						}
					}
				});
	        }
	    }
	</script>
</body>
</html>
